package com.bw.zg3park2212.order

import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.entity.OrderEntityItem
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.R
import com.bw.zg3park2212.databinding.ActivityOrderXingBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/OrderXingActivity")
class OrderXingActivity : BaseActivity<ActivityOrderXingBinding,OrderViewModel>() {
    @Autowired
    lateinit var order:OrderEntityItem
    override fun intitView() {
        ARouter.getInstance().inject(this)
        viewmodel.getorderxing(order.id)
        binding.btn.setOnClickListener {
            if (binding.btn.text=="开始巡检"){
                viewmodel.getorderstart(order.id)
            }else if(binding.btn.text=="完成巡检"){
                viewmodel.getorderend(order.id)
            }
        }

    }

    override fun intitData() {
        viewmodel.orderxingSuccse.observe(this){
            binding.address.text=it.address
            binding.appointmentTime.text=it.appointmentTime
            binding.content.text=it.content
            binding.orderType.text=it.orderType
            binding.inspector.text=it.inspector
            if(it.status=="新建"){
                binding.status.setBackgroundResource(R.drawable.bg_kongxian)
                binding.status.setTextColor(this.getColor(R.color.color_kongxian))
                binding.status.setText("新建")
                binding.btn.text="开始巡检"
            }else if(it.status=="进行中"){
                binding.status.setBackgroundResource(R.drawable.bg_zganyong)
                binding.status.setTextColor(this.getColor(R.color.color_zhanyong))
                binding.status.setText("进行中")
                binding.btn.setText("完成巡检")
            }else if(it.status=="已完成"){
                binding.status.setBackgroundResource(R.drawable.bg_weihu)
                binding.status.setTextColor(this.getColor(R.color.color_weihu))
                binding.status.setText("已完成")
                binding.btn.isVisible=false
            }else{
                binding.status.setBackgroundResource(R.drawable.bg_hui)
                binding.status.setTextColor(this.getColor(R.color.color_hui))
                binding.status.setText("已转派")
            }
        }
        viewmodel.orderstartSuccse.observe(this){
            ToastUtils.showLong("开始巡检")
            finish()
        }
        viewmodel.orderendSuccse.observe(this){
            ToastUtils.showLong("完成巡检")
            finish()
        }
    }

}